package com.util;

import com.util.IdUtils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.URL;

/**
 * java网页抓取
 *
 * @author DDN
 * @date 2024/02/07
 */
public class Main {
    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args)
            throws Exception {
        URL url = new URL("https://www.baidu.com/s?ie=utf-8&f=3&rsv_bp=1&tn=baidu&wd=%E7%9F%A5%E4%B9%8E%E7%83%AD%E6%A6%9C&oq=%25E7%259F%25A5%25E4%25B9%258E%25E6%2590%25AC%25E8%25BF%2590%25E5%25B7%25A5&rsv_pq=a0eccc24003fe235&rsv_t=65f09jDK%2BgL5tWlfQvXBX%2F%2FdDHsws89w1Ax2%2FtzH5DC1G0ks2ga6bmhe2xA&rqlang=cn&rsv_enter=1&rsv_dl=ts_6&rsv_sug3=1&rsv_sug1=2&rsv_sug7=100&rsv_sug2=1&rsv_btype=t&prefixsug=%25E7%259F%25A5%25E4%25B9%258E&rsp=6&rsv_sug4=2945&rsv_sug=1");
        String s = IdUtils.simpleUUID();
        String url2 = "D:\\JinShengYu\\页面捕获\\" + s + ".html";
        BufferedReader reader = new BufferedReader
                (new InputStreamReader(url.openStream()));
        BufferedWriter writer = new BufferedWriter
                (new FileWriter(url2));
        String line;
        while ((line = reader.readLine()) != null) {
            writer.write(line);
            writer.newLine();
        }
        reader.close();
        writer.close();
    }
}
